public class CastingNumbers {
    public static void main(String[] args) {
        double above = 0.7, below = 0.4;
        double fabove = 0.7f, fbelow = 0.4f;
        System.out.println("(int)above: " + (int) above);  // 0
        System.out.println("(int)below: " + (int) below);  // 0
        System.out.println("(int)fabove: " + (int) fabove); // 0
        System.out.println("(int)fbelow: " + (int) fbelow); // 0
        // 将float或double转换为int时，会舍弃小数部分

        System.out.println("Math.round(above): " + Math.round(above));  // 1
        System.out.println("Math.round(below): " + Math.round(below));  // 0
        System.out.println("Math.round(fabove): " + Math.round(fabove)); // 1
        System.out.println("Math.round(fbelow): " + Math.round(fbelow)); // 0
        // Math.round()方法会四舍五入到最接近的整数
    }
}
